home *** CD-ROM | disk | FTP | other *** search
/ Collection of Internet / Collection of Internet.iso / msdos / lynx / source / www / library / implemen / tcp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-25  |  15.1 KB  |  586 lines

  1. /*                                                      System dependencies in the W3 library
  2.                                    SYSTEM DEPENDENCIES
  3.                                              
  4.    System-system differences for TCP include files and macros. This file includes for each
  5.    system the files necessary for network and file I/O.  Part of libwww.
  6.    
  7.   AUTHORS
  8.   
  9.   TBL                     Tim Berners-Lee, W3 project, CERN, <timbl@info.cern.ch>
  10.  
  11.   EvA                     Eelco van Asperen <evas@cs.few.eur.nl>
  12.  
  13.   MA                      Marc Andreesen NCSA
  14.  
  15.   GB                      Garrett Arch Blythe <blythe@stat1.cc.ukans.edu>
  16.  
  17.   MD                      Mark Donszelmann <duns@vxcern.cern.ch>
  18.  
  19.   AT                      Aleksandar Totic <atotic@ncsa.uiuc.edu>
  20.  
  21.   SCW                     Susan C. Weber <sweber@kyle.eitech.com>
  22.  
  23.   HISTORY:
  24.  
  25.   22 Feb 91               Written (TBL) as part of the WWW library.
  26.  
  27.   16 Jan 92               PC code from (EvA)
  28.  
  29.   22 Apr 93               Merged diffs bits from xmosaic release
  30.  
  31.   29 Apr 93               Windows/NT code from (SCW)
  32.  
  33.   29 Sep 93               VMS fixes (MD)
  34.  
  35.   23 Nov 93               MSDOS using Wattcp code began. GB
  36.                          
  37.  */
  38.  
  39. #ifndef TCP_H
  40. #define TCP_H
  41.  
  42. /*
  43.  
  44. Default values
  45.  
  46.    These values may be reset and altered by system-specific sections later on.  there are
  47.    also a bunch of defaults at the end .
  48.  
  49.  */
  50. /* Default values of those: */
  51. #define NETCLOSE close      /* Routine to close a TCP-IP socket         */
  52. #define NETREAD  read       /* Routine to read from a TCP-IP socket     */
  53. #define NETWRITE write      /* Routine to write to a TCP-IP socket      */
  54.  
  55. /* Unless stated otherwise, */
  56. #define SELECT                  /* Can handle >1 channel.               */
  57. #define GOT_SYSTEM              /* Can call shell with string           */
  58.  
  59. #ifdef unix
  60. #define GOT_PIPE
  61. #endif
  62. #ifdef VM
  63. #define GOT_PIPE                /* Of sorts */
  64. #endif
  65.  
  66. #ifdef DECNET
  67. typedef struct sockaddr_dn SockA;  /* See netdnet/dn.h or custom vms.h */
  68. #else /* Internet */
  69. typedef struct sockaddr_in SockA;  /* See netinet/in.h */
  70. #endif
  71.  
  72.  
  73. /*
  74.  
  75. Macintosh - Think-C
  76.  
  77.    Think-C is one development environment on the Mac.
  78.    
  79.    We recommend that you compile with 4-byte ints to be compatible with MPW C.  We used
  80.    Tom Milligan's s_socket library which was written for 4 byte int, and the MacTCP
  81.    library assumes 4-byte int.
  82.    
  83.  */
  84. #ifdef THINK_C
  85. #undef GOT_SYSTEM
  86. #define DEBUG                   /* Can't put it on the CC command line  */
  87. #define NO_UNIX_IO              /* getuid() missing                     */
  88. #define NO_GETPID               /* getpid() does not exist              */
  89. #define NO_GETWD                /* getwd() does not exist               */
  90.  
  91. #undef NETCLOSE             /* Routine to close a TCP-IP socket         */
  92. #undef NETREAD              /* Routine to read from a TCP-IP socket     */
  93. #undef NETWRITE             /* Routine to write to a TCP-IP socket      */
  94. #define NETCLOSE s_close    /* Routine to close a TCP-IP socket         */
  95. #define NETREAD  s_read     /* Routine to read from a TCP-IP socket     */
  96. #define NETWRITE s_write    /* Routine to write to a TCP-IP socket      */
  97.  
  98. #define bind s_bind         /* Funny names presumably to prevent clashes */
  99. #define connect s_connect
  100. #define accept s_accept
  101. #define listen s_listen
  102. #define socket s_socket
  103. #define getsockname s_getsockname
  104.  
  105. /* The function prototype checking is better than the include files
  106. */
  107.  
  108. extern s_close(int s);
  109. extern s_read(int s, char *buffer, int buflen);
  110. extern s_write(int s, const char *buffer, int buflen);
  111.  
  112. extern bind(int s, struct sockaddr *name, int namelen);
  113. extern accept(int s, struct sockaddr *addr, int *addrlen);
  114. extern listen(int s, int qlen);
  115. extern connect(int s, struct sockaddr *addr, int addrlen);
  116.  
  117. extern s_socket(int domain, int type, int protocol);
  118. extern s_getsockname(int s, struct sockaddr *name, int *namelen);
  119. extern struct hostent *gethostent(const char * name);
  120. extern unsigned long inet_addr(const char * name);
  121.  
  122. #endif /* THINK_C */
  123.  
  124.  
  125. /*
  126.  
  127. Macintosh - MPW
  128.  
  129.    MPW is one development environment on the Mac.
  130.    
  131.    This entry was created by Aleksandar Totic (atotic@ncsa.uiuc.edu) this file is
  132.    compatible with sockets package released by NCSA.  One major conflict is that this
  133.    library redefines write/read/etc as macros.  In some of HTML code these macros get
  134.    executed when they should not be. Such files should define NO_SOCKET_DEFS on top. This
  135.    is a temporary hack.
  136.    
  137.  */
  138. #ifdef applec                   /* MPW  */
  139. #undef GOT_SYSTEM
  140. #define DEBUG                   /* Can't put it on the CC command line */
  141. #define NO_UNIX_IO              /* getuid() missing
  142. */
  143. #define NO_GETPID               /* getpid() does not exist
  144. */
  145. #define NO_GETWD                /* getwd() does not exist
  146. */
  147.  
  148. #undef NETCLOSE             /* Routine to close a TCP-IP socket */
  149. #undef NETREAD              /* Routine to read from a TCP-IP socket */
  150. #undef NETWRITE             /* Routine to write to a TCP-IP socket */
  151. #define NETCLOSE s_close    /* Routine to close a TCP-IP socket */
  152. #define NETREAD  s_read     /* Routine to read from a TCP-IP socket */
  153. #define NETWRITE s_write    /* Routine to write to a TCP-IP socket */
  154. #define _ANSI_SOURCE
  155. #define GUI
  156. #define LINEFEED 10
  157. #define ANON_FTP_HOSTNAME
  158. #ifndef NO_SOCKET_DEFS
  159. #include <MacSockDefs.h>
  160. #endif
  161.  
  162. #include <socket.ext.h>
  163. #include <string.h>
  164.  
  165. #endif                 /* MPW */
  166.  
  167.  
  168.  
  169. #ifndef STDIO_H
  170. #include <stdio.h>
  171. #define STDIO_H
  172. #endif
  173.  
  174. /*
  175.  
  176. Big Blue - the world of incompatibility
  177.  
  178. IBM RS600
  179.  
  180.    On the IBM RS-6000, AIX is almost Unix.
  181.    
  182.  */
  183. #ifdef _AIX
  184. #define AIX
  185. #endif
  186. #ifdef AIX
  187. #define unix
  188. #endif
  189.  
  190. /*    AIX 3.2
  191. **    -------
  192. */
  193.  
  194. #ifdef _IBMR2
  195. #define USE_DIRENT              /* sys V style directory open */
  196. #endif
  197.  
  198.  
  199. /*
  200.  
  201. IBM VM-CMS, VM-XA Mainframes
  202.  
  203.    MVS is compiled as for VM. MVS has no unix-style I/O.  The command line compile options
  204.    seem to come across in lower case.
  205.    
  206.  */
  207. #ifdef mvs
  208. #define MVS
  209. #endif
  210.  
  211. #ifdef MVS
  212. #define VM
  213. #endif
  214.  
  215. #ifdef NEWLIB
  216. #pragma linkage(newlib,OS)      /* Enables recursive NEWLIB */
  217. #endif
  218.  
  219. /*      VM doesn't have a built-in predefined token, so we cheat: */
  220. #ifndef VM
  221. #include <string.h>             /* For bzero etc - not  VM */
  222. #endif
  223.  
  224. /*      Note:   All include file names must have 8 chars max (+".h")
  225. **
  226. **      Under VM, compile with "(DEF=VM,SHORT_NAMES,DEBUG)"
  227. **
  228. **      Under MVS, compile with "NOMAR DEF(MVS)" to get rid of 72 char margin
  229. **        System include files TCPIP and COMMMAC neeed line number removal(!)
  230. */
  231.  
  232. #ifdef VM                       /* or MVS -- see above. */
  233. #define NOT_ASCII               /* char type is not ASCII */
  234. #define NO_UNIX_IO              /* Unix I/O routines are not supported */
  235. #define NO_GETPID               /* getpid() does not exist */
  236. #define NO_GETWD                /* getwd() does not exist */
  237. #ifndef SHORT_NAMES
  238. #define SHORT_NAMES             /* 8 character uniqueness for globals */
  239. #endif
  240. #include <manifest.h>
  241. #include <bsdtypes.h>
  242. #include <stdefs.h>
  243. #include <socket.h>
  244. #include <in.h>
  245. #include <inet.h>
  246. #include <netdb.h>
  247. #include <errno.h>          /* independent */
  248. extern char asciitoebcdic[], ebcdictoascii[];
  249. #define TOASCII(c)   (c=='\n' ?  10  : ebcdictoascii[c])
  250. #define FROMASCII(c) (c== 10  ? '\n' : asciitoebcdic[c])
  251.  
  252. #include <bsdtime.h>
  253. #include <time.h>
  254. #include <string.h>
  255. #define INCLUDES_DONE
  256. #define TCP_INCLUDES_DONE
  257. #endif
  258.  
  259.  
  260. /*
  261.  
  262. IBM-PC running MS-DOS with SunNFS for TCP/IP
  263.  
  264.    This code thanks to Eelco van Asperen <evas@cs.few.eur.nl>
  265.  
  266.  */
  267. #ifdef PCNFS
  268. #include <sys/types.h>
  269. #include <string.h>
  270. #include <errno.h>          /* independent */
  271. #include <sys/time.h>       /* independent */
  272. #include <sys/stat.h>
  273. #include <fcntl.h>          /* In place of sys/param and sys/file */
  274. #define INCLUDES_DONE
  275. #define FD_SET(fd,pmask) (*(unsigned*)(pmask)) |=  (1<<(fd))
  276. #define FD_CLR(fd,pmask) (*(unsigned*)(pmask)) &= ~(1<<(fd))
  277. #define FD_ZERO(pmask)   (*(unsigned*)(pmask))=0
  278. #define FD_ISSET(fd,pmask) (*(unsigned*)(pmask) & (1<<(fd)))
  279. #endif  /* PCNFS */
  280.  
  281. /*
  282.  
  283. IBM-PC running Windows NT
  284.  
  285.    These parameters providede by  Susan C. Weber <sweber@kyle.eitech.com>.
  286.  
  287.  */
  288. #ifdef _WINDOWS
  289. #include "fcntl.h"                      /* For HTFile.c */
  290. #include "sys\types.h"                  /* For HTFile.c */
  291. #include "sys\stat.h"                   /* For HTFile.c */
  292.  
  293. #undef NETREAD
  294. #undef NETWRITE
  295. #undef NETCLOSE
  296. #define NETREAD(s,b,l)  ((s)>10 ? recv((s),(b),(l),0) : read((s),(b),(l)))
  297. #define NETWRITE(s,b,l) ((s)>10 ? send((s),(b),(l),0) : write((s),(b),(l)))
  298. #define NETCLOSE(s)     ((s)>10 ? closesocket(s) : close(s))
  299. #include <io.h>
  300. #include <string.h>
  301. #include <process.h>
  302. #include <time.h>
  303. #include <direct.h>
  304. #include <stdio.h>
  305. #include <winsock.h>
  306. typedef struct sockaddr_in SockA;  /* See netinet/in.h */
  307. #define INCLUDES_DONE
  308. #define TCP_INCLUDES_DONE
  309. #endif  /* WINDOWS */
  310.  
  311. #ifdef MSDOS
  312. /*
  313.  *     GB 11-19-93
  314.  *      IBM PC using the Waterloo TCP/IP library, Borland C++ 3.1
  315.  */
  316. #include"msdostcp.h"
  317. #define INCLUDES_DONE
  318. #define TCP_INCLUDES_DONE
  319. #endif /* MSDOS */
  320.  
  321. /*
  322.  
  323. VAX/VMS
  324.  
  325.    Under VMS, there are many versions of TCP-IP. Define one if you do not use Digital's
  326.    UCX product:
  327.  
  328.   UCX                     DEC's "Ultrix connection" (default)
  329.  
  330.   WIN_TCP                 From Wollongong, now GEC software.
  331.  
  332.   MULTINET                From SRI, now from TGV Inv.
  333.  
  334.   DECNET                  Cern's TCP socket emulation over DECnet
  335.  
  336.    The last three do not interfere with the unix i/o library, and so they need special
  337.    calls to read, write and close sockets. In these cases the socket number is a VMS
  338.    channel number, so we make the @@@ HORRIBLE @@@ assumption that a channel number will
  339.    be greater than 10 but a unix file descriptor less than 10.  It works.
  340.  
  341.  */
  342. #ifdef vms
  343. #define CACHE_FILE_PREFIX  "SYS$LOGIN:Z_"
  344.  
  345. #ifdef WIN_TCP
  346. #undef NETREAD
  347. #undef NETWRITE
  348. #undef NETCLOSE
  349. #define NETREAD(s,b,l)  ((s)>10 ? netread((s),(b),(l)) : read((s),(b),(l)))
  350. #define NETWRITE(s,b,l) ((s)>10 ? netwrite((s),(b),(l)) : write((s),(b),(l)))
  351. #define NETCLOSE(s)     ((s)>10 ? netclose(s) : close(s))
  352. #endif
  353.  
  354. #ifdef MULTINET
  355. #undef NETCLOSE
  356. #undef NETREAD
  357. #undef NETWRITE
  358. #define NETREAD(s,b,l)  ((s)>10 ? socket_read((s),(b),(l)) : read((s),(b),(l)))
  359. #define NETWRITE(s,b,l) ((s)>10 ? socket_write((s),(b),(l)) : \
  360.                                 write((s),(b),(l)))
  361. #define NETCLOSE(s)     ((s)>10 ? socket_close(s) : close(s))
  362. #endif
  363.  
  364. #ifdef DECNET
  365. #undef SELECT  /* not supported */
  366. #undef NETREAD
  367. #undef NETWRITE
  368. #undef NETCLOSE
  369. #define NETREAD(s,b,l)  ((s)>10 ? recv((s),(b),(l),0) : read((s),(b),(l)))
  370. #define NETWRITE(s,b,l) ((s)>10 ? send((s),(b),(l),0) : write((s),(b),(l)))
  371. #define NETCLOSE(s)     ((s)>10 ? socket_close(s) : close(s))
  372. #endif /* Decnet */
  373.  
  374. /*      Certainly this works for UCX and Multinet; not tried for Wollongong
  375. */
  376. #ifdef MULTINET
  377. #include "multinet_root:[multinet.include.sys]types.h"
  378. #include "multinet_root:[multinet.include]errno.h"
  379. #include "multinet_root:[multinet.include.sys]time.h"
  380. #else
  381. #include types
  382. #include errno
  383. #include time
  384. #endif /* multinet */
  385.  
  386. #include string
  387.  
  388. #ifndef STDIO_H
  389. #include stdio
  390. #define STDIO_H
  391. #endif
  392.  
  393. #include file
  394.  
  395. #ifndef DECNET  /* Why is it used at all ? Types conflict with "types.h" */
  396. #include unixio
  397. #endif
  398.  
  399. #define INCLUDES_DONE
  400.  
  401. #ifdef MULTINET  /* Include from standard Multinet directories */
  402. #include "multinet_root:[multinet.include.sys]socket.h"
  403. #ifdef __TIME_LOADED  /* defined by sys$library:time.h */
  404. #define __TIME  /* to avoid double definitions in next file */
  405. #endif
  406. #include "multinet_root:[multinet.include.netinet]in.h"
  407. #include "multinet_root:[multinet.include.arpa]inet.h"
  408. #include "multinet_root:[multinet.include]netdb.h"
  409.  
  410. #else  /* not multinet */
  411. #ifdef DECNET
  412. #include "types.h"  /* for socket.h */
  413. #include "socket.h"
  414. #include "dn"
  415. #include "dnetdb"
  416. /* #include "vms.h" */
  417.  
  418. #else /* UCX or WIN */
  419. #include socket
  420. #include in
  421. #include inet
  422. #include netdb
  423.  
  424. #endif  /* not DECNET */
  425. #endif  /* of Multinet or other TCP includes */
  426.  
  427. #define TCP_INCLUDES_DONE
  428.  
  429. /*
  430.  
  431.    On VMS machines, the linker needs to be told to put global data sections into a data
  432.    segment using these storage classes. (MarkDonszelmann)
  433.    
  434.  */
  435. #ifdef VAXC
  436. #define GLOBALDEF globaldef
  437. #define GLOBALREF globalref
  438. #endif /*  VAXC */
  439.  
  440. #endif  /* vms */
  441.  
  442. /*
  443.  
  444.    On non-VMS machines, the GLOBALDEF and GLOBALREF storage types default to normal C
  445.    storage types.
  446.    
  447.  */
  448. #ifndef GLOBALREF
  449. #define GLOBALDEF
  450. #define GLOBALREF extern
  451. #endif
  452.  
  453.  
  454.  
  455. /*
  456.  
  457. SCO ODT unix version
  458.  
  459.  */
  460.  
  461. #ifdef sco
  462. #include <sys/fcntl.h>
  463. #define USE_DIRENT
  464. #endif
  465.  
  466. /*
  467.  
  468. MIPS unix
  469.  
  470.  */
  471. /* Mips hack (bsd4.3/sysV mixture...) */
  472.  
  473. #ifdef mips
  474. extern int errno;
  475. #endif
  476.  
  477. /*
  478.  
  479. OSF/1
  480.  
  481.  */
  482. #ifdef __osf__
  483. #define USE_DIRENT
  484. #endif /* OSF1 AXP */
  485.  
  486.  
  487. /*
  488.  
  489. Regular BSD unix versions
  490.  
  491.    These are a default unix where not already defined specifically.
  492.  
  493.  */
  494. #ifndef INCLUDES_DONE
  495. #include <sys/types.h>
  496. /* #include <streams/streams.h>                 not ultrix */
  497. #include <string.h>
  498.  
  499. #include <errno.h>          /* independent */
  500. #include <sys/time.h>       /* independent */
  501. #include <sys/stat.h>
  502. #include <sys/param.h>
  503. #include <sys/file.h>       /* For open() etc */
  504. #define INCLUDES_DONE
  505. #endif  /* Normal includes */
  506.  
  507. /*                      Directory reading stuff - BSD or SYS V
  508. */
  509. #ifdef unix                    /* if this is to compile on a UNIX machine */
  510. #define GOT_READ_DIR 1    /* if directory reading functions are available */
  511. #ifdef USE_DIRENT             /* sys v version */
  512. #include <dirent.h>
  513. #define direct dirent
  514. #else
  515. #include <sys/dir.h>
  516. #endif
  517. #if defined(sun) && defined(__svr4__)
  518. #include <sys/fcntl.h>
  519. #include <limits.h>
  520. #endif
  521. #endif
  522.  
  523. /*
  524.  
  525. Defaults
  526.  
  527.   INCLUDE FILES FOR TCP
  528.   
  529.  */
  530. #ifndef TCP_INCLUDES_DONE
  531. #include <sys/socket.h>
  532. #include <netinet/in.h>
  533. #ifndef __hpux /* this may or may not be good -marc */
  534. #include <arpa/inet.h>      /* Must be after netinet/in.h */
  535. #endif
  536. #include <netdb.h>
  537. #endif  /* TCP includes */
  538.  
  539.  
  540. /*
  541.  
  542.   MACROS FOR MANIPULATING MASKS FOR SELECT()
  543.   
  544.  */
  545. #ifdef SELECT
  546. #ifndef FD_SET
  547. typedef unsigned int fd_set;
  548. #define FD_SET(fd,pmask) (*(pmask)) |=  (1<<(fd))
  549. #define FD_CLR(fd,pmask) (*(pmask)) &= ~(1<<(fd))
  550. #define FD_ZERO(pmask)   (*(pmask))=0
  551. #define FD_ISSET(fd,pmask) (*(pmask) & (1<<(fd)))
  552. #endif  /* FD_SET */
  553. #endif  /* SELECT */
  554.  
  555. /*
  556.  
  557.   M ACROS FOR CONVERTING CHARACTERS
  558.   
  559.  */
  560. #ifndef TOASCII
  561. #define TOASCII(c) (c)
  562. #define FROMASCII(c) (c)
  563. #endif
  564.  
  565. /*
  566.  
  567.   CACHE FILE PREFIX
  568.   
  569.    This is something onto which we tag something meaningful to make a cache file name.
  570.    used in HTWSRC.c at least. If it is nor defined at all, caching is turned off.
  571.    
  572.  */
  573. #ifndef CACHE_FILE_PREFIX
  574. #ifdef unix
  575. #define CACHE_FILE_PREFIX  "/usr/wsrc/"
  576. #endif
  577. #endif
  578.  
  579. #endif /* TCP_H */
  580.  
  581.  
  582.  
  583. /*
  584.  
  585.    end of system-specific file */
  586.